package com.undefined.socket.server;

import com.undefined.bean.User;

import java.io.InputStream;
import java.io.ObjectInputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class SocketServer {
    public static void main(String[] args) throws Exception {
        // 监听指定的端口
        int port = 55533;
        ServerSocket server = new ServerSocket(port);

        // server将一直等待连接的到来
        System.out.println("server将一直等待连接的到来");
        Socket socket = server.accept();
        // 建立好连接后，从socket中获取输入流，并建立缓冲区进行读取
        InputStream inputStream = socket.getInputStream();


        ObjectInputStream ois = new ObjectInputStream(inputStream);
        User user = (User) ois.readObject();

        System.out.println("读取到客户端的消息:" + user);
        inputStream.close();
        socket.close();
        server.close();
    }
}
